#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

class program {
public:
    int start_time;
    int end_time;

    bool operator<(const program &P) const {
        return end_time < P.end_time;
    }
} buf_data[100];

int main(int argc, char const *argv[]) {
    int n;
    while (scanf("%d", &n) != EOF) {
        if (n == 0)
            break;
        for (int i = 0; i < n; ++i)
            scanf("%d%d", &buf_data[i].start_time, &buf_data[i].end_time);
        sort(buf_data, buf_data + n);
        int current_time = 0, result = 0;
        for (int i = 0; i < n; ++i) {
            if (current_time <= buf_data[i].start_time) {
                current_time = buf_data[i].end_time;
                result++;
            }
        }
        printf("%d\n", result);
    }
    return 0;
}